﻿#Region "Matrix预配置参数"
Public Class MatrixSettings
    Inherits MatrixSetting

    Private _Items As New Collection
    Private _ListFormItems = New ArrayList


    ''' <summary>
    ''' 添加预配置信息
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub Add()
        Dim tmpMs As New MatrixSetting
        With tmpMs
            .MtxUID = Me.MtxUID
            .TableName = Me.TableName
            .AutoLineKeyCol = Me.AutoLineKeyCol
            .MenuAddNewLine = Me.MenuAddNewLine
            .PrimaryLineCol = Me.PrimaryLineCol
            .TableKeyField = Me.TableKeyField
            .TableVisOrder = Me.TableVisOrder
            .addButtonUID = Me.addButtonUID
            .delButtonUID = Me.delButtonUID
            .PaneLevel = Me.PaneLevel
            .AutoAddNewLine = Me.AutoAddNewLine
            .AffectsFormModeAddRow = Me.AffectsFormModeAddRow
            .AffectsFormModeDelRow = Me.AffectsFormModeDelRow
            .BeforeSaveDeleteNoValueLine = Me.BeforeSaveDeleteNoValueLine
            .NotAllowNoLineSave = Me.NotAllowNoLineSave '是否允许MTX中无数据添加【2010-12-6】--wp
            .BeforeSaveFixDbDataSourceData = Me.BeforeSaveFixDbDataSourceData
            .AddLineAfterButtonPressed = Me.AddLineAfterButtonPressed
            .DeleteLineAfterButtonPressed = Me.DeleteLineAfterButtonPressed
            Me.MatrixSettingItems.Add(tmpMs, tmpMs.MtxUID)
            If _ListFormItems.Contains(.addButtonUID) = False Then
                Me._ListFormItems.Add(.addButtonUID)
            End If
            If _ListFormItems.Contains(.delButtonUID) = False Then
                Me._ListFormItems.Add(.delButtonUID)
            End If
        End With
        With Me '清空配置信息
            .MtxUID = Nothing
            .TableName = Nothing
            .AutoLineKeyCol = Nothing
            .MenuAddNewLine = Nothing
            .PrimaryLineCol = Nothing
            .TableKeyField = Nothing
            .TableVisOrder = Nothing
            .addButtonUID = Nothing
            .delButtonUID = Nothing
            .PaneLevel = Nothing
            .BeforeSaveDeleteNoValueLine = Nothing
            .BeforeSaveFixDbDataSourceData = Nothing
            .NotAllowNoLineSave = Nothing
            .AddLineAfterButtonPressed = True
            .DeleteLineAfterButtonPressed = True
        End With
    End Sub

    Public Function RelationshipFormItem(ByVal ItemUID As String) As Boolean
        If Me._ListFormItems.Contains(ItemUID) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Sub MatrixSettingRemove(ByVal Key As String)
        Me.MatrixSettingItems.Remove(Key)
    End Sub

    Public Function MatrixSettingItem(ByVal Key As String) As MatrixSetting
        Return _Items.Item(Key)
    End Function

    Public ReadOnly Property MatrixSettingItems() As Collection
        Get
            Return _Items
        End Get
    End Property

    Public Function Exists(ByVal Key As String) As Boolean
        If Me._Items.Contains(Key) = True Then
            Return True
        Else
            Return False
        End If
    End Function
    ''' <summary>
    ''' 根据按钮获取MatrixSetting
    ''' </summary>
    ''' <param name="butUID">按钮UID</param>
    ''' <param name="butType">区分按钮类型-添加、删除</param>
    ''' <param name="PaneLevel">层级</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetButtonMatrix(ByVal butUID As String, ByRef butType As ButtonType, ByVal PaneLevel As Integer) As MatrixSetting
        Dim mts As MatrixSetting
        For Each mts In Me.MatrixSettingItems
            If mts.addButtonUID = butUID And mts.PaneLevel = PaneLevel Then
                butType = ButtonType.bt_AddLine
                Return mts
            End If
            If mts.delButtonUID = butUID And mts.PaneLevel = PaneLevel Then
                butType = ButtonType.bt_DelLine
                Return mts
            End If
        Next
        Return Nothing
    End Function

    Public Enum ButtonType
        bt_AddLine = 0
        bt_DelLine = 1
    End Enum
End Class

Public Class MatrixSetting
    Private _MtxUID As String
    Private _TableName As String
    Private _AutoLineKeyCol As String
    Private _PrimaryLineCol As String
    Private _tableKeyField As String = "LineId"
    Private _tableVisOrderField As String = "VisOrder"
    Private _AffectsFormModeAddRow As Boolean = False
    Private _AffectsFormModeDelRow As Boolean = True
    Private _delItemUID As String
    Private _addItemUID As String
    Private _AutoAddNewLine As Boolean = True
    Private _MenuAddNewLine As Boolean = True
    Private _PaneLevel As Integer
    Private _befSaveLoadData As Boolean = False
    Private _befSaveDelNoKeyColValue As Boolean = True
    Private _NotAllowNoLine As Boolean = True
    Private _BeforeSaveFixDbDataSourceData As Boolean = False
    Private _UpdateDataTodbDataSource As Boolean = False
    Private _AddLineAfterButtonPressed As Boolean = True
    Private _DeleteLineAfterButtonPressed As Boolean = True

    ''' <summary>
    ''' 删除钮按下 是否删除行
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property DeleteLineAfterButtonPressed As Boolean
        Get
            Return _DeleteLineAfterButtonPressed
        End Get
        Set(value As Boolean)
            _DeleteLineAfterButtonPressed = value
        End Set
    End Property

    ''' <summary>
    ''' 添加钮按下 是否添加行
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property AddLineAfterButtonPressed As Boolean
        Get
            Return _AddLineAfterButtonPressed
        End Get
        Set(value As Boolean)
            _AddLineAfterButtonPressed = value
        End Set
    End Property

    ''' <summary>
    ''' 更新Matrix数据到dbds
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property UpdateDataTodbDataSource As Boolean
        Get
            Return _UpdateDataTodbDataSource
        End Get
        Set(value As Boolean)
            _UpdateDataTodbDataSource = value
        End Set
    End Property

    ''' <summary>
    ''' 保存前去除空数据行
    ''' 如果matrix没有行，B1会自动给matrix加入空行。
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property BeforeSaveFixDbDataSourceData As Boolean
        Get
            Return _BeforeSaveFixDbDataSourceData
        End Get
        Set(ByVal value As Boolean)
            _BeforeSaveFixDbDataSourceData = value
        End Set
    End Property


    ''' <summary>
    ''' 不允许没有行
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property NotAllowNoLineSave() As Boolean
        Get
            Return _NotAllowNoLine
        End Get
        Set(ByVal value As Boolean)
            _NotAllowNoLine = value
        End Set
    End Property

    ''' <summary>
    ''' 保存前是否删除关键列（AutoLineKeyCol）为空的行
    ''' 且刷新DataSource数据到matrix界面
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property BeforeSaveDeleteNoValueLine() As Boolean
        Get
            Return _befSaveDelNoKeyColValue
        End Get
        Set(ByVal value As Boolean)
            _befSaveDelNoKeyColValue = value
        End Set
    End Property

    '''' <summary>
    '''' 保存数据时，刷新DataSource数据到matrix界面
    '''' </summary>
    '''' <value></value>
    '''' <returns></returns>
    '''' <remarks></remarks>
    'Public Property BeforeSaveLoadData() As Boolean
    '    Get
    '        Return _befSaveLoadData
    '    End Get
    '    Set(ByVal value As Boolean)
    '        _befSaveLoadData = value
    '    End Set
    'End Property

    ''' <summary>
    ''' 是否完成关键数据后自动添加matrix行
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property AutoAddNewLine() As Boolean
        Get
            Return Me._AutoAddNewLine
        End Get
        Set(ByVal value As Boolean)
            Me._AutoAddNewLine = value
        End Set
    End Property
    ''' <summary>
    ''' 右击添加行菜单
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property MenuAddNewLine() As Boolean
        Get
            Return Me._MenuAddNewLine
        End Get
        Set(ByVal value As Boolean)
            Me._MenuAddNewLine = value
        End Set
    End Property
    ''' <summary>
    ''' 添加、删除行后是否改变窗体状态
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property AffectsFormModeAddRow() As Boolean
        Get
            Return _AffectsFormModeAddRow
        End Get
        Set(ByVal value As Boolean)
            _AffectsFormModeAddRow = value
        End Set
    End Property

    ''' <summary>
    ''' 添加、删除行后是否改变窗体状态
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property AffectsFormModeDelRow() As Boolean
        Get
            Return _AffectsFormModeDelRow
        End Get
        Set(ByVal value As Boolean)
            _AffectsFormModeDelRow = value
        End Set
    End Property

    ''' <summary>
    ''' MtxUID
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property MtxUID() As String
        Get
            Return _MtxUID
        End Get
        Set(ByVal value As String)
            _MtxUID = value
        End Set
    End Property

    ''' <summary>
    ''' 对应关键dbdatesource名称
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property TableName() As String
        Get
            Return _TableName
        End Get
        Set(ByVal value As String)
            _TableName = value
        End Set
    End Property

    ''' <summary>
    ''' table的关键字段
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property TableKeyField() As String
        Get
            Return Me._tableKeyField
        End Get
        Set(ByVal value As String)
            Me._tableKeyField = value
        End Set
    End Property

    ''' <summary>
    ''' table的序号字段
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property TableVisOrder() As String
        Get
            Return Me._tableVisOrderField
        End Get
        Set(ByVal value As String)
            Me._tableVisOrderField = value
        End Set
    End Property

    ''' <summary>
    ''' 添加行检查列字段
    ''' 值为空则加行，否则不加行
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property AutoLineKeyCol() As String
        Get
            Return _AutoLineKeyCol
        End Get
        Set(ByVal value As String)
            _AutoLineKeyCol = value
        End Set
    End Property

    ''' <summary>
    ''' matrix主键字段
    ''' 删除行关键字段
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property PrimaryLineCol() As String
        Get
            Return _PrimaryLineCol
        End Get
        Set(ByVal value As String)
            _PrimaryLineCol = value
        End Set
    End Property

    ''' <summary>
    ''' 删除mtx行，绑定按钮
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property delButtonUID() As String
        Get
            Return Me._delItemUID
        End Get
        Set(ByVal value As String)
            Me._delItemUID = value
        End Set
    End Property

    ''' <summary>
    ''' 添加mtx行，绑定按钮
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property addButtonUID() As String
        Get
            Return Me._addItemUID
        End Get
        Set(ByVal value As String)
            Me._addItemUID = value
        End Set
    End Property

    ''' <summary>
    ''' Matrix所在的PaneLevel
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property PaneLevel() As Integer
        Get
            Return Me._PaneLevel
        End Get
        Set(ByVal value As Integer)
            Me._PaneLevel = value
        End Set
    End Property
End Class
#End Region
